<?php

namespace app\common\lib;

class Str
{
    /**
     * 生成登录所需的token
     * @param $string
     * @return string
     */
    public static function getLoginToken($string){
        //生成token
        $str = md5(uniqid(md5(microtime(true)),true)); //生成一个不会重复的字符串
        $token = sha1($str.$string); //加密
        return $token;
    }

    /**
     * 生成唯一单号
     * @param $shopId
     * @param $typeId 1订单 2配送单 3订货单 4拉水单 5调拨单 6入库单 7出库单
     * @return string
     */
    public static function makeOrderNo($shopId,$typeId)
    {
        $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
        $orderSn =
            $yCode[intval(date('Y')) - 2025] . $yCode[intval(date('Y')) - 2024] . $shopId . $typeId . date("Ymd",time()) . strtoupper(dechex(date('m'))) . date(
                'd') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf(
                '%02d', rand(0, 99));
        return $orderSn;
    }
}
